package org.csu.canteen.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.canteen.entity.Coupon;
import org.csu.canteen.entity.CouponPackage;
import org.csu.canteen.persistence.CouponMapper;
import org.csu.canteen.persistence.CouponPackageMapper;
import org.csu.canteen.service.CouponService;
import org.csu.canteen.vo.CouponPackageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("couponService")
public class CouponServiceImpl implements CouponService {
    @Autowired
    private CouponMapper couponMapper;

    @Autowired
    private CouponPackageMapper couponPackageMapper;

    @Override
    public void insertCoupon(CouponPackage couponPackage) {
        couponPackageMapper.insert(couponPackage);
    }

    @Override
    public CouponPackageVO searchCouponByUsername(String username) {
        CouponPackageVO couponPackageVO=new CouponPackageVO();

        //条件查询
        QueryWrapper<CouponPackage> queryWrapper=new QueryWrapper<>();
        //构造条件
        queryWrapper.eq("username",username);
        List<CouponPackage> couponPackageList =couponPackageMapper.selectList(queryWrapper);

        couponPackageVO.setCouponList(couponPackageList);
        return couponPackageVO;
    }

    @Override
    public void deleteCouponByUsernameAndID(CouponPackage couponPackage) {
        couponPackageMapper.deleteById(couponPackage.getUsername());
    }

    //coupon表数据
    @Override
    public Coupon searchCouponByID(int couponID) {
        return couponMapper.selectById(couponID);
    }
}
